		
	Date.prototype.format = function(fmt) {
		var o = {
			"M+" : this.getMonth() + 1, //月份 
			"d+" : this.getDate(), //日 
			"h+" : this.getHours(), //小时 
			"m+" : this.getMinutes(), //分 
			"s+" : this.getSeconds(), //秒 
			"q+" : Math.floor((this.getMonth() + 3) / 3), //季度 
			"S" : this.getMilliseconds()//毫秒 
		};
		
		if (/(y+)/.test(fmt))
			fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "")
					.substr(4 - RegExp.$1.length));
		for ( var k in o)
			if (new RegExp("(" + k + ")").test(fmt))
				fmt = fmt.replace(RegExp.$1,
						(RegExp.$1.length == 1) ? (o[k])
								: (("00" + o[k])
										.substr(("" + o[k]).length)));
		return fmt;
	};
	
	$(".btn-default").click(function(){
		$.ajax({
			url:'localTrain/find',
			type:'post',
			datatype:'json',
			contentType:'application/json;charset=utf-8',
			data:JSON.stringify({  				
				'trainName':$("#train_name").val(),
				'startStationName':$("#start_station_name").val(),
				'endStationName':$("#end_station_name").val(),
				'findStartTime':$("#find_start_time").val(),
				'findEndTime':$("#find_end_time").val()
			}),
			success: function(res){
				console.log('成功了');
				if(res.length>0){
					var trainName = $("#train_name").val();
					var dateList = new Array(res.length);
					var hardSeatList = new Array(res.length);
					var hardSleeperList = new Array(res.length);
					var softSleeperList = new Array(res.length);
					var normalSeatList = new Array(res.length);
					var firstClassList = new Array(res.length);
					var secondClassList = new Array(res.length);
					var noSeatList = new Array(res.length);
					var principalSeatList = new Array(res.length);
					for(i=0;i<res.length;i++){
						
						dateList[i]=new Date(res[i].create_time).format("yyyy-MM-dd hh:mm:ss");
						
						if(null===res[i].hard_seat_last){
							hardSeatList[i]=0;
						}else{
							hardSeatList[i]=res[i].hard_seat_last;
						}
						
						if(null===res[i].hard_sleeper_last){
							hardSleeperList[i]=0;
						}else{
							hardSleeperList[i]=res[i].hard_sleeper_last;
						}
						
						if(null===res[i].soft_sleeper_last){
							softSleeperList[i]=0;
						}else{
							softSleeperList[i]=res[i].soft_sleeper_last;
						}
						
						if(null===res[i].normal_seat_last){
							normalSeatList[i]=0;
						}else{
							normalSeatList[i]=res[i].normal_seat_last;
						}
						
						if(null===res[i].first_class_seat_last){
							firstClassList[i]=0;
						}else{
							firstClassList[i]=res[i].first_class_seat_last;
						}
						
						if(null===res[i].second_class_seat_last){
							secondClassList[i]=0;
						}else{
							secondClassList[i]=res[i].second_class_seat_last;
						}
						
						if(null===res[i].no_seat_last){
							noSeatList[i]=0;
						}else{
							noSeatList[i]=res[i].no_seat_last;
						}
						
						if(null===res[i].principal_seat_last){
							principalSeatList[i]=0;
						}else{
							principalSeatList[i]=res[i].principal_seat_last;
						}
						
					}
					$(".container").empty();
					// 基于准备好的dom，初始化echarts实例
					var mainContainer = document.getElementById('main');
					//用于使chart自适应高度和宽度,通过窗体高宽计算容器高宽
			        var resizeMainContainer = function () {
			            mainContainer.style.width = window.innerWidth+'px';
			            mainContainer.style.height = window.innerHeight*0.8+'px';
			        };
			        //设置div容器高宽
			        resizeMainContainer();
					var myChart = echarts.init(mainContainer);
					 $(window).on('resize',function(){//
			            //屏幕大小自适应，重置容器高宽
			            resizeMainContainer();
			            mainChart.resize();
			       });
			        // 指定图表的配置项和数据
			        option = {
			    title : {
			        text: trainName+'列车历史车票波动',
			        subtext: '来源携程查询'
			    },
				 // 提示框
			     tooltip : {
			         trigger: 'axis'
			    },
				// 线条标识
			    legend: {
//			    	 data:['最高气温','最低气温']
			        data:['硬座','硬卧','软卧','商务座','一等座','二等座','无座','特等座']
			    },
			    toolbox: {
			        show : true,
			        feature : {
			            mark : {show: true},
			            dataView : {show: true, readOnly: false},
			            magicType : {show: true, type: ['line', 'bar']},
			            restore : {show: true},
			            saveAsImage : {show: true}
			        }
			    },
			    calculable : true,
			    xAxis : [
			        {
			            type : 'category',
			            boundaryGap : false,
//			            data : ['周一','周二','周三','周四','周五','周六','周日']
			            data: dateList
			        }
			    ],
			    yAxis : [
			        {
			            type : 'value',
			            axisLabel : {
			                formatter: '{value} 张'
			            }
			        }
			    ],
			    series : [
			        {
			            name:'硬座',
			            type:'line',
			            data:hardSeatList,
			            markPoint : {
			                data : [
			                    {type : 'max', name: '最大值'},
			                    {type : 'min', name: '最小值'}
			                ]
			            },
			            markLine : {
			                data : [
			                    {type : 'average', name: '平均值'}
			                ]
			            }
			        },
			        {
			            name:'硬卧',
			            type:'line',
			            data:hardSleeperList,
			            markPoint : {
			                data : [
			                    {type : 'max', name: '最大值'},
			                    {type : 'min', name: '最小值'}
			                ]
			            },
			            markLine : {
			                data : [
			                    {type : 'average', name: '平均值'}
			                ]
			            }
			        },
			        {
			            name:'软卧',
			            type:'line',
			            data:softSleeperList,
			            markPoint : {
			                data : [
			                    {type : 'max', name: '最大值'},
			                    {type : 'min', name: '最小值'}
			                ]
			            },
			            markLine : {
			                data : [
			                    {type : 'average', name: '平均值'}
			                ]
			            }
			        },
			        {
			            name:'商务座',
			            type:'line',
			            data:normalSeatList,
			            markPoint : {
			                data : [
			                    {type : 'max', name: '最大值'},
			                    {type : 'min', name: '最小值'}
			                ]
			            },
			            markLine : {
			                data : [
			                    {type : 'average', name: '平均值'}
			                ]
			            }
			        },
			        {
			            name:'一等座',
			            type:'line',
			            data:hardSeatList,
			            markPoint : {
			                data : [
			                    {type : 'max', name: '最大值'},
			                    {type : 'min', name: '最小值'}
			                ]
			            },
			            markLine : {
			                data : [
			                    {type : 'average', name: '平均值'}
			                ]
			            }
			        },
			        {
			            name:'一等座',
			            type:'line',
			            data:firstClassList,
			            markPoint : {
			                data : [
			                    {type : 'max', name: '最大值'},
			                    {type : 'min', name: '最小值'}
			                ]
			            },
			            markLine : {
			                data : [
			                    {type : 'average', name: '平均值'}
			                ]
			            }
			        },
			        {
			            name:'二等座',
			            type:'line',
			            data:secondClassList,
			            markPoint : {
			                data : [
			                    {type : 'max', name: '最大值'},
			                    {type : 'min', name: '最小值'}
			                ]
			            },
			            markLine : {
			                data : [
			                    {type : 'average', name: '平均值'}
			                ]
			            }
			        },
			        {
			            name:'无座',
			            type:'line',
			            data:noSeatList,
			            markPoint : {
			                data : [
			                    {type : 'max', name: '最大值'},
			                    {type : 'min', name: '最小值'}
			                ]
			            },
			            markLine : {
			                data : [
			                    {type : 'average', name: '平均值'}
			                ]
			            }
			        },
			        {
			            name:'特等座',
			            type:'line',
			            data:principalSeatList,
			            markPoint : {
			                data : [
			                    {type : 'max', name: '最大值'},
			                    {type : 'min', name: '最小值'}
			                ]
			            },
			            markLine : {
			                data : [
			                    {type : 'average', name: '平均值'}
			                ]
			            }
			        }
			    ]
			};
			        // 使用刚指定的配置项和数据显示图表。
			        myChart.setOption(option);
				}
				
			},
			error: function(res){
				console.log('失败了');
			}	
		})
	})
	

	
